{include file="public/header,public/nav,public/fixbar" title="会员储值-<?php echo request()->pc_info['seo_title']?>"/}
<div class="layui-body">
    <div class="layui-container">
        <div class="layui-col-space15">
            <!-- 菜单栏 -->
            <div class="layui-col-xs12 layui-col-sm4 layui-col-md4 layui-col-lg3">
                <div class="layui-main user-main min-height-90vh">
                    {include file="user/menu"/}
                </div>
            </div>
            <div class="layui-col-xs12 layui-col-sm8 layui-col-md8 layui-col-lg9">
                <div class="layui-main user-main min-height-90vh">
                    <h2>会员储值</h2>
                    <blockquote class="layui-elem-quote">
                        <div class="user-income space-between">
                            <p class="layui-font-success">
                                <span class="layui-font-black">账户余额：</span>
                                <b class="layui-font-30" style="font-family: DIN;">{$money}</b>
                                <span class="layui-font-12">元</span>
                            </p>
                            <a class="layui-btn layui-bg-success layui-btn-sm recharge">立即充值</a>
                        </div>
                    </blockquote>
                    <div class="layui-tab layui-tab-brief margin-bottom-10">
                        <ul class="layui-tab-title">
                            <li class="layui-this select-type" data-type="0">全部</li>
                            <li class="select-type" data-type="1">余额明细</li>
                            <li class="select-type" data-type="2">订单消费</li>
                        </ul>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-space15 scrollbar height-600" id="balance-list">
                            
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer"/}
<script type="text/javascript">
    layui.use(['flow','layer'], function(){
        var layer = layui.layer, flow = layui.flow, $=layui.jquery;
        
        var type = 0;
        $(function(){
            loadList(type);  // 加载列表
        })

        // 根据类型读取
        $(".select-type").on('click', function(){
            type = $(this).data('type');
            $('#balance-list').html('');
            loadList(type);
        });

        // 分页加载列表
        function loadList(type){
            var limit = 10;//每次请求的条数
            flow.load({
                elem: '#balance-list' //指定列表容器
                ,scrollElem: '#balance-list'//滚动条所在元素
                ,end: '—— 已经到底了~ ——'
                ,done: function(page, next){ //到达临界点（默认滚动触发），触发下一页的回调
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        data: {'page': page, 'limit':limit, 'type':type},//请求的页码和每页显示条数
                        url: '/user/balance',
                        success: function (res) {
                            var lis = [];
                            if(res.code == 0){
                                if (res.data.length > 0) {
                                    
                                    var newsHtml = '';
                                    layui.each(res.data, function(index, item){
                                        var flag = '';
                                        if (item.amount < 0) {
                                            flag = 'layui-font-red';
                                        }
                                        newsHtml += `<div class="layui-col-xs12">
                                            <div class="layui-panel" style="border: none;border-bottom: 1px solid #f2f2f2;">
                                                <div class="space-between">
                                                    <div>
                                                        <p>${item.remark}</p>
                                                        <p style="margin-top: 5px;color: #999;">${item.create_time}</p>
                                                    </div>
                                                    <div style="text-align: right;">
                                                        <p class="layui-font-success">
                                                            <b class="layui-font-16 ${flag}">${item.amount}</b>
                                                        </p>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>`;
                                    });
                                    
                                    lis.push(newsHtml);
                                    //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
                                    //res.total为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
                                    next(lis.join(''), page < Math.ceil(res.count/limit));
                                    
                                } else {
                                    $('#balance-list').html('<div class="layui-empty"><img src="/static/images/nodata/no_income.png"><p>暂无相关数据~</p></div>');
                                }
                            } else {
                                layer.msg(res.msg, {icon:2, time: 1500});
                            }
                        }
                        ,error:function(e){
                            layer.closeAll();
                            layer.msg("请求失败："+e.msg, {icon:2, time: 1500});
                        },
                    });
                }
            });
        }

        // 余额充值
        $(document).on('click', '.recharge', function(){
            layer.confirm('暂不支持PC端余额充值，请你使用APP/微信小程序等手机客户端进行余额充值。', {
                skin: 'layui-layer-radius', // 弹窗主题样式
                title : '提示',
                area: '420px',
                btn: ['知道了', '取消'],
            },function(index){
                layer.close(index);
            })
        })
    });

</script>